import request from '@/utils/request'

export function login(data) {
  return request({
    url: '/admin/user/login',
    method: 'post',
    data
  })
}

export function getInfo(token) {
  return request({
    url: '/admin/user/info',
    method: 'get',
  })
}

export function logout() {
  return request({
    url: '/admin/user/logout',
    method: 'post'
  })
}

// 查询管理员列表的处理
export function listUser(query) {
  return request({
    url: '/admin/user/getAdminList',
    method: 'get',
    params: query
  })
}

// 添加管理员
export function addUser(data) {
  return request({
    url: '/admin/user/addUser',
    method: 'post',
    data: data
  })
}

// 查询用户详细
export function getUser(userId) {
  return request({
    url: '/admin/user/userInfo/' + parseStrEmpty(userId),
    method: 'get'
  })
}

// 修改admin的处理
export function updateAdmin(data) {
  return request({
    url: '/admin/user/updateAdmin',
    method: 'put',
    data: data
  })
}

// 删除admin的处理
export function deleteById(ids) {
  const query={
    ids
  }
  return request({
    url:'/admin/user/deleteById',
    method:'delete',
    params: query,
    paramsSerializer:function (params){
      return qs.stringify(params,{arrayFormat:'repeat'})
    }
  })
}


// Admin密码重置
export function resetUserPwd(userId, password) {
  const data = {
    userId,
    password
  }
  return request({
    url: '/admin/user/resetPwd',
    method: 'put',
    data: data
  })
}


// 显示用户个人信息
export function getUserProfile() {
  return request({
    url: '/admin/user/profile',
    method: 'get'
  })
}

// 用户密码重置
export function updateUserPwd(oldPassword, newPassword) {
  const data = {
    oldPassword,
    newPassword
  }
  return request({
    url: '/admin/user/updatePwd',
    method: 'put',
    params: data
  })
}

// 用户头像上传
export function addImage(data) {
  return request({
    url: '/admin/user/addImage',
    method: 'post',
    data: data
  })
}
